package com.hmys.api.controller;

import com.hmys.api.model.WebVideo;
import com.hmys.api.model.WebWeather;
import com.hmys.api.response.Result;
import com.hmys.api.response.ResultCode;
import com.hmys.api.service.WebWeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2018/04/12.
 */
@RestController
@Api(tags = "天气")
@RequestMapping(value = "/weather")
public class WeatherController {

    @Autowired
    private WebWeatherService webWeatherService;

    @ApiOperation(value = "详情", notes = "详情", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "cid", value = "和风城市ID", required = true, paramType = "path")
    })
    @GetMapping(value = "/detail/{cid}")
    public Object detail(@PathVariable("cid") String cid) {
        if (StringUtils.isEmpty(cid)) {
            return new Result<>(ResultCode.ERROR_PARAM);
        }
        WebWeather record = webWeatherService.selectByCid(cid);
        if (record != null) {
            if (record.getStatus()) {
                return new Result<>(ResultCode.SUCCESS, record);
            } else {
                return new Result<>(ResultCode.HAVE_DELETED);
            }
        } else {
            return new Result<>(ResultCode.NOT_FOUND);
        }
    }
}
